using System.Data;
using System.Data.SqlClient;

namespace VMukti.DataAccess.VMuktiGrid
{
    public class ClsTabDataService : ClsDataServiceBase
    {
        public ClsTabDataService() : base() { }

        public ClsTabDataService(IDbTransaction txn) : base(txn) { }

        public DataSet GetTabs(int intPageId)
        {
            return ExecuteDataSet("select * from tabs where pageid=" + intPageId + "and IsDeleted='False'" , CommandType.Text, null);
        }

        public int AddTab(int intTabId, int intPageId, int intTabPosition, string strTabTitle, string strTabDesc, int intUserId, double C1Width, double C2Width, double C3Width)
        {
            SqlCommand cmd;
            int id;
            ExecuteNonQuery(out cmd, "spAETabs",
                CreateParameter("@pID", SqlDbType.BigInt, intTabId),
                CreateParameter("@pPageID", SqlDbType.BigInt, intPageId),
                CreateParameter("@pTabPosition", SqlDbType.Int, intTabPosition),
                CreateParameter("@pTabTitle", SqlDbType.NVarChar, strTabTitle),
                CreateParameter("@pDescription", SqlDbType.NVarChar, strTabDesc),
                CreateParameter("@pGivenID", SqlDbType.BigInt, intUserId),
                CreateParameter("@pC1Width", SqlDbType.Float, C1Width),
                CreateParameter("@pC2Width", SqlDbType.Float, C2Width),
                CreateParameter("@pC3Width", SqlDbType.Float, C3Width),
                CreateParameter("@pReturnMaxID", SqlDbType.BigInt, ParameterDirection.Output));

            id = int.Parse(cmd.Parameters["@pReturnMaxID"].Value.ToString());
            cmd.Dispose();
            return id;
        }

        public int GetMaxTabId()
        {
            SqlCommand cmd;
            int id;
            ExecuteNonQuery(out cmd, "spGMaxTabId",
                CreateParameter("@pReturnMaxID", SqlDbType.BigInt, ParameterDirection.Output));
            id = int.Parse(cmd.Parameters["@pReturnMaxID"].Value.ToString());
            cmd.Dispose();
            return id;
        }

        public void RemoveTab(int intTabId)
        {
            ExecuteDataSet("spDTabs", CommandType.StoredProcedure, CreateParameter("@pID", SqlDbType.BigInt, intTabId));
        }

        public DataSet GetTabPage(int intPageId)
        {
            
            return ExecuteDataSet("spGTabPage", CreateParameter("@pID", SqlDbType.Int, intPageId));
        }

        public DataSet GetTab(int intTabid)
        {
            return ExecuteDataSet("select * from Tabs where id=" + intTabid + "and isdeleted='False'", CommandType.Text, null);
        }

    }
}